package com.yc.demo.test02;

import com.google.gson.Gson;
import com.yc.demo.bean.Result;
import com.yc.demo.bean.User;
import com.yc.demo.d0303.LoginServlet;
import com.yc.demo.d0304.OnlineListener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Arrays;

@WebServlet(name = "OnlineServlet", value = "/OnlineServlet.s")
public class OnlineServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取在线人数
        int size = OnlineListener.onlinedUser.size();
        Result result = new Result();
        User u = LoginServlet.user;
        result.setCode(size);
        result.setData(OnlineListener.onlinedUser);

        Gson gson = new Gson();
        response.getWriter().append(gson.toJson(result));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
